<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
</head>
<body>
    <button>1</button>
    <button>2</button>
    <button>3</button>
    <button>4</button>
    <button>5</button>
</body>
</html>
<script>
    //判断数组中的数组
    //获取所有按钮
    var btns= document.querySelectorAll('button');
    //遍历按钮
    for(var i=0;i<btns.length;i++){
        btns[i].onclick=function(){
            for(var i=0;i<btns.length;i++){
                btns[i].style.backgroundColor=''
            }
            this.style.backgroundColor='pink'
            this.style.color='#fff'
        }
    }
</script>